<template>
    <div>
        <ul>
            <li v-for='(item) in list' :key='item.id'>
                {{item.name}}
                {{item.price}} <button @click='addCart'>加入购物车</button>
            </li>
        </ul>
    </div>
</template>
<script>
// 引入vuex辅助函数
import {mapActions} from 'vuex';
export default {
    name:' home',
    data(){
        return{
            title:'',  
            list:[],     
             }
    },
    created(){
        this.getData();
    },
    methods: {
        ...mapActions(['addCart']),
        getData(){
          
          //console.log('this.$http:',this.$http);
          this.$http.get('http://localhost:8080/api/goods.json')
          .then(res=>{
           console.log("res::",res)
           if(res.status==200 && res.data.status==2){
               console.log(res.data.content)
               this.list=res.data.content;
           }
          })
        }
    },
}
</script>
<style>
    
</style>